//
//  registViewController.m
//  百车易车险
//
//  Created by chenxu on 15/3/9.
//  Copyright (c) 2015年 chenxu. All rights reserved.
//

#import "registViewController.h"
#import "NetAPIManager.h"
@implementation registViewController



- (void)viewDidLoad{
    [super viewDidLoad];
    _myuser = [[User alloc]init];
    _submitBtn.layer.cornerRadius = kCornerRadius;
    [_submitBtn setPopingPressed];
   // self.view.backgroundColor = kColorTableSectionBg;
    sheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"你的出生地?",@"你母亲的名字?",@"高中班主任的名字?",@"你父亲的名字?",nil];
}



/*!
 *  @brief  提交注册信息
 *  @param sender 按钮
 */
- (IBAction)submit:(id)sender {
    _myuser.Username = [_namefield text];
    _myuser.Password = [_passfield text];
    _myuser.registPass = [_confirmpassfield text];
    _myuser.Question = _question;
    _myuser.Answer = [_answerfield text];
    if ([_myuser registUserTips]) {
        [self showHudTipStr:[_myuser registUserTips]];
        
    }
    else{
        //发送post请求
        [[NetAPIManager sharedManager] request_Register_WithParams:[_myuser toRegistParams] andBlock:^(id data, NSError *error) {
            if (data) {
                NSLog(@"成功注册");
                [Login doLogin:[_myuser toSaveUserParams]];
                [self performSegueWithIdentifier:@"registsuccess" sender:self];
            }else{
                NSLog(@"注册失败");
            }
        }];
    }
    
    
    
}

- (IBAction)turnnext:(id)sender {
    [_passfield becomeFirstResponder];
    [UIView up:self.view length:100];
}

- (IBAction)turnnext2:(id)sender {
    [_confirmpassfield becomeFirstResponder];
    [UIView up:self.view length:100];

}

- (IBAction)turnnext3:(id)sender {
    [UIView down:self.view];

}

- (IBAction)completeinput:(id)sender {
    [_answerfield resignFirstResponder];
    [UIView down:self.view];
}

- (IBAction)chooseQuestion:(id)sender {
    
   
    
    [sheet showInView:self.view];
}

#pragma mark - picker view
#pragma mark Actionsheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString* temp = _questionLabel.text;
    switch (buttonIndex) {
        case 0:
            _questionLabel.text = [temp stringByAppendingString:@" 你的出生地?"];
            _question = @"你的出生地?";
            [_chooseBtn setHidden:YES];
            break;
        case 1:
            _questionLabel.text = [temp stringByAppendingString:@" 你母亲的姓名"];
            _question = @"你母亲的姓名?";
            [_chooseBtn setHidden:YES];

            break;
        case 2:
            _questionLabel.text = [temp stringByAppendingString:@" 高中班主任的名字?"];
            _question = @"高中班主任的名字?";

            [_chooseBtn setHidden:YES];

            break;
        case 3:
            _questionLabel.text = [temp stringByAppendingString:@" 你父亲的生日?"];
            _question = @"你父亲的生日?";
            [_chooseBtn setHidden:YES];

    }
}

- (IBAction)begin1:(id)sender {
    [UIView up:self.view length:100];
}





@end
